package org.jivesoftware.smack.packet;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.util.StringUtils;

public class RosterPacket extends IQ
{
  private final List<Item> rosterItems = new ArrayList();
  private String version;

  public void addRosterItem(Item paramItem)
  {
    synchronized (this.rosterItems)
    {
      this.rosterItems.add(paramItem);
      return;
    }
  }

  // ERROR //
  public String getChildElementXML()
  {
    // Byte code:
    //   0: new 39	java/lang/StringBuilder
    //   3: dup
    //   4: invokespecial 40	java/lang/StringBuilder:<init>	()V
    //   7: astore_1
    //   8: aload_1
    //   9: ldc 42
    //   11: invokevirtual 46	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   14: pop
    //   15: aload_0
    //   16: getfield 48	org/jivesoftware/smack/packet/RosterPacket:version	Ljava/lang/String;
    //   19: ifnull +32 -> 51
    //   22: aload_1
    //   23: new 39	java/lang/StringBuilder
    //   26: dup
    //   27: ldc 50
    //   29: invokespecial 53	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   32: aload_0
    //   33: getfield 48	org/jivesoftware/smack/packet/RosterPacket:version	Ljava/lang/String;
    //   36: invokevirtual 46	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   39: ldc 55
    //   41: invokevirtual 46	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   44: invokevirtual 58	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   47: invokevirtual 46	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   50: pop
    //   51: aload_1
    //   52: ldc 60
    //   54: invokevirtual 46	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   57: pop
    //   58: aload_0
    //   59: getfield 27	org/jivesoftware/smack/packet/RosterPacket:rosterItems	Ljava/util/List;
    //   62: astore 4
    //   64: aload 4
    //   66: monitorenter
    //   67: aload_0
    //   68: getfield 27	org/jivesoftware/smack/packet/RosterPacket:rosterItems	Ljava/util/List;
    //   71: invokeinterface 64 1 0
    //   76: astore 6
    //   78: aload 6
    //   80: invokeinterface 70 1 0
    //   85: ifne +18 -> 103
    //   88: aload 4
    //   90: monitorexit
    //   91: aload_1
    //   92: ldc 72
    //   94: invokevirtual 46	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   97: pop
    //   98: aload_1
    //   99: invokevirtual 58	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   102: areturn
    //   103: aload_1
    //   104: aload 6
    //   106: invokeinterface 76 1 0
    //   111: checkcast 6	org/jivesoftware/smack/packet/RosterPacket$Item
    //   114: invokevirtual 79	org/jivesoftware/smack/packet/RosterPacket$Item:toXML	()Ljava/lang/String;
    //   117: invokevirtual 46	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   120: pop
    //   121: goto -43 -> 78
    //   124: astore 5
    //   126: aload 4
    //   128: monitorexit
    //   129: aload 5
    //   131: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   67	91	124	finally
    //   103	129	124	finally
  }

  public int getRosterItemCount()
  {
    synchronized (this.rosterItems)
    {
      int i = this.rosterItems.size();
      return i;
    }
  }

  public Collection<Item> getRosterItems()
  {
    synchronized (this.rosterItems)
    {
      List localList2 = Collections.unmodifiableList(new ArrayList(this.rosterItems));
      return localList2;
    }
  }

  public String getVersion()
  {
    return this.version;
  }

  public void setVersion(String paramString)
  {
    this.version = paramString;
  }

  public static class Item
  {
    private final Set<String> groupNames;
    private RosterPacket.ItemStatus itemStatus;
    private RosterPacket.ItemType itemType;
    private String name;
    private String user;

    public Item(String paramString1, String paramString2)
    {
      this.user = paramString1.toLowerCase();
      this.name = paramString2;
      this.itemType = null;
      this.itemStatus = null;
      this.groupNames = new CopyOnWriteArraySet();
    }

    public void addGroupName(String paramString)
    {
      this.groupNames.add(paramString);
    }

    public Set<String> getGroupNames()
    {
      return Collections.unmodifiableSet(this.groupNames);
    }

    public RosterPacket.ItemStatus getItemStatus()
    {
      return this.itemStatus;
    }

    public RosterPacket.ItemType getItemType()
    {
      return this.itemType;
    }

    public String getName()
    {
      return this.name;
    }

    public String getUser()
    {
      return this.user;
    }

    public void removeGroupName(String paramString)
    {
      this.groupNames.remove(paramString);
    }

    public void setItemStatus(RosterPacket.ItemStatus paramItemStatus)
    {
      this.itemStatus = paramItemStatus;
    }

    public void setItemType(RosterPacket.ItemType paramItemType)
    {
      this.itemType = paramItemType;
    }

    public void setName(String paramString)
    {
      this.name = paramString;
    }

    public String toXML()
    {
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append("<item jid=\"").append(this.user).append("\"");
      if (this.name != null)
        localStringBuilder.append(" name=\"").append(StringUtils.escapeForXML(this.name)).append("\"");
      if (this.itemType != null)
        localStringBuilder.append(" subscription=\"").append(this.itemType).append("\"");
      if (this.itemStatus != null)
        localStringBuilder.append(" ask=\"").append(this.itemStatus).append("\"");
      localStringBuilder.append(">");
      Iterator localIterator = this.groupNames.iterator();
      while (true)
      {
        if (!(localIterator.hasNext()))
        {
          localStringBuilder.append("</item>");
          return localStringBuilder.toString();
        }
        String str = (String)localIterator.next();
        localStringBuilder.append("<group>").append(StringUtils.escapeForXML(str)).append("</group>");
      }
    }
  }

  public static class ItemStatus
  {
    public static final ItemStatus SUBSCRIPTION_PENDING = new ItemStatus("subscribe");
    public static final ItemStatus UNSUBSCRIPTION_PENDING = new ItemStatus("unsubscribe");
    private String value;

    private ItemStatus(String paramString)
    {
      this.value = paramString;
    }

    public static ItemStatus fromString(String paramString)
    {
      ItemStatus localItemStatus;
      if (paramString == null)
        localItemStatus = null;
      while (true)
      {
        while (true)
        {
          String str;
          while (true)
          {
            return localItemStatus;
            str = paramString.toLowerCase();
            if (!("unsubscribe".equals(str)))
              break;
            localItemStatus = UNSUBSCRIPTION_PENDING;
          }
          if (!("subscribe".equals(str)))
            break;
          localItemStatus = SUBSCRIPTION_PENDING;
        }
        localItemStatus = null;
      }
    }

    public String toString()
    {
      return this.value;
    }
  }

  public static enum ItemType
  {
    static
    {
      from = new ItemType("from", 2);
      both = new ItemType("both", 3);
      remove = new ItemType("remove", 4);
      ItemType[] arrayOfItemType = new ItemType[5];
      arrayOfItemType[0] = none;
      arrayOfItemType[1] = to;
      arrayOfItemType[2] = from;
      arrayOfItemType[3] = both;
      arrayOfItemType[4] = remove;
      ENUM$VALUES = arrayOfItemType;
    }
  }
}